package com.wondertek.web.controller.business;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wondertek.common.base.Result;
import com.wondertek.common.util.security.PreAuthorize;
import com.wondertek.service.dto.app.res.DeviceErrorRecordListRes;
import com.wondertek.service.dto.business.req.WebDerReq;
import com.wondertek.service.service.business.DeviceErrorRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangyu
 */
@RestController
@RequestMapping("/backend/business/fault")
@Tag(name = "故障中心")
public class FaultController {

    @Autowired
    private DeviceErrorRecordService deviceErrorRecordService;

    /**
     * web查询报警
     * @return
     */
    @PostMapping("/page")
    @Operation(summary = "故障分页查询")
    @PreAuthorize("@el.check('backend:business:fault:page')")
    public Result<Page<DeviceErrorRecordListRes>> page(@RequestBody WebDerReq req){
       req.setType(2);
       return Result.success(deviceErrorRecordService.findWebRecordList(req));
    }

    @GetMapping("/updateReadById")
    @Operation(summary = "根据id修改已读状态")
    public Result updateReadById(@RequestParam("id") String id){
        deviceErrorRecordService.updateWebReadById(id);
        return Result.success();
    }

    @PostMapping("/export")
    @Operation(summary = "导出故障信息")
    public void export(@RequestBody WebDerReq req, HttpServletResponse response) {
        req.setType(2);
        deviceErrorRecordService.export(req, response);
    }
}
